public class suo {
    public static void main(String[] args) {
        change s = new change();
        new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                try {
                    s.increase();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"A").start();
        new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                try {
                    s.decrease();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        },"C").start();
        new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                try {
                    s.decrease();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        },"D").start();
        new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                try {
                    s.increase();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        },"E").start();
        new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                try {
                    s.decrease();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        },"B").start();

    }

}
class change{
    private int i = 0;
    public synchronized void increase() throws InterruptedException {
        while (i != 0){
            wait();
        }
        System.out.println(Thread.currentThread().getName()+"+"+i);
        i += 1;
        notifyAll();
    }
    public synchronized void decrease() throws InterruptedException {
        while (i != 1){
            wait();
        }
        System.out.println(Thread.currentThread().getName()+"+"+i);
        i -= 1;
        notifyAll();
    }
}